package design.action.memento;

import lombok.Getter;
import lombok.ToString;

/**
 * @author zxs
 * @since 2020/05/29
 */
@Getter
@ToString
public class ConcreteOriginator extends AbstractOriginator {

    private String state;

    public ConcreteOriginator(String name,Caretaker caretaker) {
        super(name,caretaker);
    }

    @Override
    public Memento createMemento() {
        ConcreteMemento m = new ConcreteMemento();
        m.setState(state);
        return m;
    }

    @Override
    public void recoveryMemento(Memento memento) {
        if(memento instanceof ConcreteMemento){
            ConcreteMemento m = (ConcreteMemento)memento;
            this.state = m.getState();
        }
    }

    public void setState(String state){
        super.storeMemento();
        this.state = state;
    }

}
